<template>
  <el-form
    ref="ruleForm"
    :model="ruleForm"
    status-icon
    :rules="rules"
    label-width="80px"
    class="demo-ruleForm"
  >
    <el-form-item label="昵称：" prop="nickname">
      <el-input v-model="ruleForm.nickname"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" size="mini" @click="submit('ruleForm')">提交</el-button>
      <el-button type="danger" size="mini" @click="close">关闭</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updateAmend } from '@/api/profile'
export default {
  data () {
    return {
      ruleForm: {
        nickname: ''
      },
      rules: {
        nickname: [
          { required: true, message: '昵称不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submit (formName) {
      console.log(this.$refs[formName])
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateAmend({
            nickname: this.ruleForm.nickname
          }).then(this.$message.success('修改昵称成功！'))
        }
      })
    },
    close () {
      this.$router.push({ path: '/home' })
    }
  }
}
</script>

<style>
</style>
